/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sorting;

/**
 *
 * @author Akram Mellice
 */
public final class InsertionSort<T extends Comparable> extends Sort<T> {

    public InsertionSort(T[] array, Class<T> classType) {
        super(array, classType);
    }

    /**
     * Sort using the Insertion Sort algorithm
     * This sort is stable
     */
    @Override
    public void sort() {
        int j = 0;
        for (int i = 1; i < array.length; i++) {
            j = i;
            while (j > 0 && array[j].compareTo(array[j - 1]) < 0) {
                T tmp = array[j - 1];
                array[j - 1] = array[j];
                array[j] = tmp;
                j--;
            }
        }
    }
}
